package com.zhigh.project.security.jwt.authentication;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class InMemorySecretHolder implements SecretHolder<JWT> {


    private final Map<String, String> secretMap = new ConcurrentHashMap<>();

    public InMemorySecretHolder() {
    }

    @Override
    public String getSecret(JWT jwt) {
        return jwt == null ? null : secretMap.get(jwt.getSignature());
    }

    @Override
    public void saveSecret(JWT jwt, String secret) {
        if (jwt == null) return;
        secretMap.put(jwt.getSignature(), secret);
    }
}
